import React, { Component } from "react";
import Template from "components/UI/template";
import { AdvancedTable } from "components/index";
import { queryCurrencyPrecision, messages } from "share/common";
import httpFetch from "share/httpFetch";

const { Middle } = Template;

class TotalView extends Component {
  columns = [
    { title: messages("finance-10.key66") /*单据公司*/, dataIndex: "companyName", width: 240, minWidth: 180 },
    { title: messages("common.department") /*部门*/, dataIndex: "departmentName", width: 240, minWidth: 180 },
    { title: messages("finance-10.key67") /*供应商*/, dataIndex: "vendorName" },
    { title: messages("common.expense.type") /*费用类型*/, dataIndex: "expenseTypeName" },
    {
      title: messages("finance-10.key69") /*成本中心*/ + "1",
      dataIndex: "costCenterCode01",
      render: (value, record) => (value ? `${record.costCenterName01} - ${value}` : "-"),
    },
    {
      title: messages("finance-10.key69") /*成本中心*/ + "2",
      dataIndex: "costCenterCode02",
      render: (value, record) => (value ? `${record.costCenterName02} - ${value}` : "-"),
    },
    {
      title: messages("finance-10.key69") /*成本中心*/ + "3",
      dataIndex: "costCenterCode03",
      render: (value, record) => (value ? `${record.costCenterName03} - ${value}` : "-"),
    },
    {
      title: messages("finance-10.key69") /*成本中心*/ + "4",
      dataIndex: "costCenterCode04",
      render: (value, record) => (value ? `${record.costCenterName04} - ${value}` : "-"),
    },
    {
      title: messages("finance-10.key69") /*成本中心*/ + "5",
      dataIndex: "costCenterCode05",
      render: (value, record) => (value ? `${record.costCenterName05} - ${value}` : "-"),
    },
    {
      title: messages("finance-10.key69") /*成本中心*/ + "6",
      dataIndex: "costCenterCode06",
      render: (value, record) => (value ? `${record.costCenterName06} - ${value}` : "-"),
    },
    {
      title: messages("finance-10.key69") /*成本中心*/ + "7",
      dataIndex: "costCenterCode07",
      render: (value, record) => (value ? `${record.costCenterName07} - ${value}` : "-"),
    },
    { title: messages("common.currency") /*币种*/, dataIndex: "currencyCode", stableWidth: 100 },
    {
      title: messages("finance-10.key71") /*预提金额*/,
      dataIndex: "totalAmount",
      render: (value, record) => this.filterMoney(value, queryCurrencyPrecision(record.currencyCode)),
    },
    { title: messages("finance-10.key47") /*本币币种*/, dataIndex: "baseCurrencyCode", stableWidth: 100 },
    {
      title: messages("finance-10.key72") /*本币预提金额*/,
      dataIndex: "baseTotalAmount",
      render: (value, record) => this.filterMoney(value, queryCurrencyPrecision(record.baseCurrencyCode)),
    },
  ];

  service = (page, size) => {
    const { accruedExpenseBatchId } = this.props.params;
    return httpFetch.get(`/api/accrued/expense/batch/summary/query`, {
      page,
      size,
      accruedExpenseBatchId,
    });
  };

  render() {
    return (
      <Template>
        <Middle>
          <AdvancedTable.SimpleTable
            service={this.service}
            columns={this.columns}
            searchForm={[]}
            index
            rowKey="accruedExpenseDetailId"
          />
        </Middle>
      </Template>
    );
  }
}

export default TotalView;
